package org.itboys.mobile.controller.web;

import org.itboys.commons.CommonConstants;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.dao.TianJieWalletRecordMapper;
import org.itboys.mobile.service.mongo.mobile.TianJieMobileCollectionService;
import org.itboys.mobile.service.mongo.mobile.TianJieMobileMemberService;
import org.itboys.mobile.service.SundayTestService;
import org.itboys.mobile.service.mysql.mobile.TianJieMobileWalletUtilService;
import org.itboys.mobile.service.mysql.web.TianJieWalletService;
import org.itboys.mobile.util.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：江雄
 * 日期：2017年5月10日
 * 描述：天街_金融_消费卡_充值产品_controller_web
 */
@Controller
@RequestMapping("/tianjie/web/finance/test")
public class TianJieTestController extends BaseController{

    @Autowired
    private TianJieMobileWalletUtilService walletUtilService;
    @Autowired
    private TianJieMobileMemberService memberService;
    @Autowired
    private TianJieWalletRecordMapper walletRecordMapper;
    @Autowired
    private TianJieMobileCollectionService collectionService;
    @Autowired
    private TianJieWalletService walletService;
    @Autowired
    private SundayTestService testService;

    /**
     * 测试
     * @param request
     * @param response
     */
   @RequestMapping("/t1")
    public void t1(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value="type",required = true)Integer type){
        try {
            testService.getTradeRecord(type);
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/tianjie/web/finance/wallet/product/save------" + e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
    @RequestMapping("/t2")
    public void t2(
            HttpServletRequest request,
            HttpServletResponse response
          ){
        try {
            testService.test2();
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/tianjie/web/finance/wallet/product/save------" + e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
   /*@RequestMapping("/t2")
    public void t2(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value="memberId",required = true)Long memberId,
            @RequestParam(value="chargeAmount",required = true)BigDecimal chargeAmount
            ){
        try {
            walletService.charge(memberId,chargeAmount);
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/tianjie/web/finance/wallet/product/save------" + e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
   @RequestMapping("/t3")
    public void t3(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value="memberId",required = true)Long memberId,
            @RequestParam(value="chargeAmount",required = true)BigDecimal chargeAmount){
        try {
            TianJieWallet wallet=walletUtilService.findByMemberId(memberId);
            TianJieWalletRecord walletRecord=new TianJieWalletRecord( memberId,  wallet.getId(), SundayCommonConstants.wallet_record_type_charge, "万品天街-消费卡充值-未支付", wallet.getUnreleaseAmount(),chargeAmount, SundayCommonConstants.NO);
            walletRecordMapper.insert(walletRecord);
            walletUtilService.charge_callback(walletRecord,"测试支付---");
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/tianjie/web/finance/wallet/product/save------" + e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }*/
  /*  @RequestMapping("/t4")
    public void t4(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value="memberIds",required = true)List<Long> memberIds){
        try {
            for(Long memberId:memberIds){
                collectionService.addCollection(memberId, 1l, 3);
            }
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/tianjie/web/finance/wallet/product/save------" + e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }*/

}
